package ModelLayer;
import java.util.ArrayList;

public class ProductList
{
    
    public ArrayList<Product> products;
    private static ProductList instance;


    public ProductList()
    {
       
        products = new ArrayList<Product>();
    }
    
    public static ProductList getInstance()
    {
        if (instance == null)
        {
            instance = new ProductList();
        }
        return instance;
    }
  
    public void addProduct (Product newProduct)
    {
        products.add(newProduct);
    }
    
    public int size()
    {
    	return products.size();
    }
    
     public void deleteProduct(int productId)
    {
        Product product = findProduct(productId);
        products.remove(product);
    }
    
    public Product findProduct(int productId)
    {
        boolean productFound = false;
        int index = 0;
        while(index < products.size() && !productFound)
        {
            Product s = products.get(index);
            if(s.getId() == productId)
            {
                productFound = true;
            }
            else
            {
                index++;
            }
    

        }
        
        if(productFound)
        {
            return products.get(index);
        }
        else
        {
          
            return null;
        }
    }
    public Product findProductName(String productName)
    {
        boolean productFound = false;
        int index = 0;
        while(index < products.size() && !productFound)
        {
            Product s = products.get(index);
            if(s.getProductName() == productName)
            {
                productFound = true;
            }
            else
            {
                index++;
            }
    

        }
        
        if(productFound)
        {
            return products.get(index);
        }
        else
        {
          
            return null;
        }
    }
}